package com.hdax.dm.item.controller;

import com.hdax.dm.entity.item.ItemType;
import com.hdax.dm.item.dto.AreaDto;
import com.hdax.dm.item.service.ItemSearchService;
import com.hdax.dm.utils.CommonResponse;
import com.hdax.dm.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品搜索控制器
 */
@RestController
@RequestMapping(path = "/item")
public class ItemSearchController {

    @Autowired
    private ItemSearchService itemSearchService;

    /**
     * 根据params查询一、二级分类
     * @return
     */
    @PostMapping(path = "list/sortgoods")
    public CommonResponse<List<ItemType>> sortgoods(@RequestBody Map<String,Long> param){
        List<ItemType> itemTypes = itemSearchService.itemTypes(param.get("param") == null ? 0 : param.get("param"));
        return ResponseUtil.returnSuccess(itemTypes);
    }

    /**
     * 查询城市列表信息
     */
    @PostMapping(path = "list/querycity")
    public CommonResponse<List<AreaDto>> querycity(){
        return ResponseUtil.returnSuccess(itemSearchService.queryCities());
    }

}
